package com.paomi.client.activity.onlineSeat;

import android.app.Activity;
import android.content.Intent;

import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter;
import com.paomi.client.activity.detail.model.DetailTicketBean;
import com.paomi.client.activity.detail.model.OnlineSiteBean;
import com.paomi.client.activity.detail.model.PlanBean;
import com.paomi.client.activity.onlineSeat.model.SeatBean;
import com.paomi.client.activity.pay.PayActivity;
import com.paomi.client.fragment.first.model.BannerBean;
import com.paomi.client.net.Api;
import com.paomi.client.net.BaseCallback;
import com.paomi.client.net.Constants;
import com.paomi.client.utils.Datas;
import com.paomi.client.view.LoadingDialog;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;

/**
 * Created by pc on 2018/12/3
 * Describe:在线选座数据请求
 * com.paomi.client.activity.onlineSeat
 */
public class OnlinePresenter extends MvpBasePresenter<OnlineMvpview> {
    /**
     *
     * @param goodsId 演出Id
     * @param planId 场次Id
     */
    public void getOnlinData(String goodsId,String planId){
        LoadingDialog.get().showLoading();
        Map<String,String> maps=new HashMap<>();
        maps.put("goodsId",goodsId);
        maps.put("goodsPlanId",planId);
        Api.getInstanceService(Constants.Ticket_URL).getOnlineSite(maps).enqueue(new BaseCallback<OnlineSiteBean>() {
            @Override
            public void onResponse(Call<OnlineSiteBean> call, OnlineSiteBean result) {
//                getView().setOnlineData(result.getReturnData());
            }
        });
    }
    /**
     * 校验能否下单
     *
     * @param goodId 演出ID
     * @param planId 演出场次ID
     *               goodsTicketJson	true	演出座次JSON串 {'112107' : '1', '112108':'1'} key 演出座次ID value 购买数量
     */
    public void getIsOrderCan(DetailTicketBean.TicketBean goodId, PlanBean planId, Activity mcontext, String json, List<SeatBean> seatData) {
        LoadingDialog.get().showLoading();
        Map<String, String> stringMap = new HashMap<>();
        stringMap.put("goodsId", ""+planId.getGoodsId());
        stringMap.put("goodsPlanId", ""+planId.getId());
        stringMap.put("goodsTicketJson", json);
        Api.getInstanceService(Constants.Pay_URL).isOrderCan(stringMap).enqueue(new BaseCallback<BannerBean>() {
            @Override
            public void onResponse(Call<BannerBean> call, BannerBean result) {
                LoadingDialog.get().hideLoading();
                Intent intent = new Intent(mcontext, PayActivity.class);
                intent.putExtra("detail", (Serializable) goodId);//演出数据
                intent.putExtra("plan", (Serializable) planId);//选择场次数据
                intent.putExtra("getSeats", (Serializable) seatData);//选择票价以及座位数据
                intent.putExtra("getData", Datas.toJsonString(result.getReturnData()));//选择场次数据
                mcontext.startActivity(intent);
            }
        });
    }
}
